#include<bits/stdc++.h>
using namespace std;
typedef struct{
	int l,r;
}AD;
bool cmp(AD A,AD B)
{
	return (A.l == B.l ? A.r > B.r : A.l < B.l);
}
AD b[500011],k[500011];
int id;
int mnr[500011];
int a[500011];
int n,m;
int q[500011],l,r;
long long f[500011];
long long w[500011];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	freopen("gonna.in","r",stdin);
	freopen("gonna.out","w",stdout);
	cin >> n;
	for(int i = 1;i <= n;i++)
		cin >> a[i];
	cin >> m;
	for(int i = 1;i <= m;i++)
		cin >> b[i].l >> b[i].r;
	sort(b + 1,b + m + 1,cmp);
	mnr[m + 1] = INT_MAX;
	for(int i = m;i;i--)
		mnr[i] = min(mnr[i + 1],b[i].r);
	for(int i = 1;i <= m;i++) if(b[i].r < mnr[i + 1])
		k[++id] = b[i];
	q[l = 0] = 0,r = 1;
	for(int s = 1;s <= id;s++)
	{
		for(int i = k[s - 1].r + 1;i <= k[s].r;i++)
		{
			w[i] = f[s - 1] + a[i];
			while(l < r && q[l] < k[s].l)
				l++;
			while(l < r && w[q[r - 1]] >= w[i])
				r--;
			q[r++] = i;
		}
		f[s] = w[q[l]];
	}
	cout << f[id] << "\n";
	return 0;
}